package com.xinzi.apartment.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xinzi.apartment.dao.BuildingInfoDao;
import com.xinzi.apartment.entity.BuildingInfoEntity;
import com.xinzi.apartment.service.BuildingInfoService;
import com.xinzi.apartment.common.utils.PageUtils;
import com.xinzi.apartment.common.utils.Query;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Map;


@Service("buildingInfoService")
public class BuildingInfoServiceImpl extends ServiceImpl<BuildingInfoDao, BuildingInfoEntity> implements BuildingInfoService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<BuildingInfoEntity> queryWrapper = new QueryWrapper<>();

        String key = (String) params.get("key");
        if(!StringUtils.isEmpty(key)) {
            //有查询条件
            queryWrapper.eq("flat_no", key).or()
                    .eq("floor_num", key).or()
                    .eq("room_num", key);
        }

        IPage<BuildingInfoEntity> page = this.page(
                new Query<BuildingInfoEntity>().getPage(params),
                queryWrapper
        );

        return new PageUtils(page);
    }

}